Hi Moray,
Set the Resolution in KMotionCNC | Tool Setup | Trajectory Planner | Counts/inch. KMotionCNC doesn't have all Lathe functionality. It is mainly missing single point threading. It might not be too hard to add. The Mach3 Lathe application works very well with KFLOP so there hasn't been a big demand for it.
The enable signals to the drives are usually required so that whenever the KFLOP axis channels become disabled that the drives also disable. Otherwise any amplifier offset from zero may cause the motor to drift. See the watchenable.c example.
For spindle feedback KFLOP requires A B Quadrature from and encoder. You might be able to trick it by phase delaying the pulse signal for the other necessary channel (RC
Circuit). But that won't work for stops or reversals. If you don't need feedback for threading or speed control then you could just run open loop by commanding to a DAC.
Your C Program's Thread layout would be possible. I would use that arrangement for debugging. But we like to minimize the number of threads used for normal operation. So it is usually best to combine everything that needs to be done continuously onto one loop placed at the end of your Init Program. So then running Init will initialize everything and then loop doing safety and modbus. This way Init, Safety, and
Modbus only use one thread and nothing else needs to be launched. Home can run temporarily in a different thread while homing.
Regarding Tool Changes. The basic sequence is that the Mach3 Macros (M6 begin/end) run in Mach3. Those Macros can perform NotifyPlugins to send data to KFLOP or to cause C Code in KFLOP to execute. The overall sequence can be split between Mach3 and KFLOP. It is sort of your choice but anything real-time must be performed in KFLOP.
HTH Regards TK
Group: DynoMotion |
Message: 8576 |
From: moray_cuthill |
Date: 11/5/2013 |
Subject: Re: Looking for some thread guidance |
Hi Tom, I'd only been using KMotionCNC to make sure the axis enabled fine and would move when commanded, however I was curious how the units got set as I hadn't found a setting anywhere. I dug out the scope tonight and checked why I'm not getting any B signals from the spindle encoder. Turns out it's simply been crippled by cutting the wires where they enter the housing, and not soldering them to the encoder board. The board is generating the differential signals, so I just need to add in a couple bits of wire. It would be nice to have spindle speed maintained relatively near the commanded speed, however what would be the best way to set it up so the VFD and KFlop aren't fighting against each other? Run open loop and run a basic lookup table if needed so commanded speed roughly matches actual speed, or is there some easy way to close the loop so I don't end up with surging? I'm sure I'll have some more questions, but I'm aiming to get the basics working first then build from there. Thanks Moray ---In dynomotion@yahoogroups.com, <tk@...> wrote:
Hi Moray,
Set the Resolution in KMotionCNC | Tool Setup | Trajectory Planner | Counts/inch. KMotionCNC doesn't have all Lathe functionality. It is mainly missing single point threading. It might not be too hard to add. The Mach3 Lathe application works very well with KFLOP so there hasn't been a big demand for it.
The enable signals to the drives are usually required so that whenever the KFLOP axis channels become disabled that the drives also disable. Otherwise any amplifier offset from zero may cause the motor to drift. See the watchenable.c example.
For spindle feedback KFLOP requires A B Quadrature from and encoder. You might be able to trick it by phase delaying the pulse signal for the other necessary channel (RC
Circuit). But that won't work for stops or reversals. If you don't need feedback for threading or speed control then you could just run open loop by commanding to a DAC.
Your C Program's Thread layout would be possible. I would use that arrangement for debugging. But we like to minimize the number of threads used for normal operation. So it is usually best to combine everything that needs to be done continuously onto one loop placed at the end of your Init Program. So then running Init will initialize everything and then loop doing safety and modbus. This way Init, Safety, and
Modbus only use one thread and nothing else needs to be launched. Home can run temporarily in a different thread while homing.
Regarding Tool Changes. The basic sequence is that the Mach3 Macros (M6 begin/end) run in Mach3. Those Macros can perform NotifyPlugins to send data to KFLOP or to cause C Code in KFLOP to execute. The overall sequence can be split between Mach3 and KFLOP. It is sort of your choice but anything real-time must be performed in KFLOP.
HTH Regards TK
From: "moray.cuthill@..." <moray.cuthill@...> To: DynoMotion@yahoogroups.com Sent: Monday, November 4, 2013 4:00 PM Subject: [DynoMotion] Looking for some thread guidance
Hi, I've finally got most of my lathe wired up, have tested the servos, and am now looking to sort out the KFlop/Kanalog configuration/coding, and get it talking to Mach3. The basic specs are two +/-10V servos, currently setup to run in Speed control mode, with basic tuning carried out in the drives, and a little bit P tweaking via the Step Response Screen. I've copied all the servo config info into it's own file, and uploaded it to the KFlop and I get movement via KMotionCNC. (One quick question, where do you set the steps per unit when using KMotionCNC? I've probably missed it but I can't remember seeing it mentioned anywhere) The servo's require an enable signal from an OptoOut to activate, and there is a servo ready and a servo fault for each drive connected to 4 OptoIns. There's also a servo fault clear from an OptoOut connected to both
drives. The spindle is controlled via two FET outputs along with a 0-10V signal, and has what I thought was a full differential quadrature encoder, but turns out the B pulses are missing. What would be the best way to setup the spindle and encoder? The lathe also has a 6 position turret, which is being controlled by a CLICK PLC. The PLC needs to have the new tool position written to a memory location, then a 'Change Allowed' signal direct from an OptoOut to a PLC input activated to allow a change. There's also a hardwired 'Turret OK' signal from the PLC to an OptoIn, which is only active when the turret is locked, and at the required position. There are also a couple other inputs via the PLC. One is for the door open switch, and one for low lube. So what I'm looking for is some guidance on what to code into what thread. I'm thinking I need the
following threads- 1) Safety thread - Handles checking all the inputs that need to be valid to ensure safe operation i.e. Servos ready, Turret OK, door closed, PLC still alive... and kills everything if a fault is detected. 2) Init thread - I don't think I need to explain this one! 3) Modbus thread - continually monitors PLC reading the inputs and updating virtual bits so values can be used by other threads/Mach 4) Homing thread - each axis has a proximity switch, and I'll also use the Z pulse for best accuracy. Have I split things into suitable threads? I should manage the actual coding (the sample files are very good!), but I'm just looking for some reassurance that I've split things up suitably. My aim is that all the basic/critical controls are handled
by the KFlop, with Mach only having to act as the display, and telling the KFlop what needs done. Although one bit I'm not sure about is how to handle toolchanges. Do I rely on Mach to take over control and ensure things are clear at safe-Z, or add another thread that gets invoked when a toolchange is required? Thanks Moray
|
|
Group: DynoMotion |
Message: 8579 |
From: Tom Kerekes |
Date: 11/5/2013 |
Subject: Re: Looking for some thread guidance |
Hi Moray,
Since it seems you will have a proper encoder on the Spindle, it would be best to operate closed loop. Use an axis channel and configure it much like a Servo axis. To go at a certain RPM command the axis to Jog at the appropriate encoder counts/sec. The VFD and KFLOP should not fight. KFLOP will adjust the DAC output to get the right speed just like any Servo. The Tuning (gains) will need to be set so the corrections are gradual enough such that too much
correction is made before the VFD has a chance to react, otherwise the system will become unstable. Can a negative voltage be applied to reverse the Spindle? Do you need to Reverse the spindle or servo it to a position?
Regards TK
Group: DynoMotion |
Message: 8581 |
From: moray_cuthill |
Date: 11/5/2013 |
Subject: Re: Looking for some thread guidance |
Hi Tom, the VFD is setup with two relays to control direction (FET2 + 3), along with a 0-10V feed (Analogue Out 2) Ultimately I'd like to be able to rigid tap to within a mm/one revolution target, however I'm not sure the current VFD and motor setup would be capable of it, so I'll be happy to settle for a reasonably accurate forward and reverse for now. The VFD is a good 20 years old (it's a KEB Combivert F0), and although capable of accepting a +/-10V signal according to the manual, the settings are locked out by an unknown password. I did consider changing it to use the +/-10V setting, but I had a search for a new VFD with a similar input and couldn't find any, so opted to stick with the more common 0-10V and relays for direction. I also considered wiping the settings completely, however the motor is a bit oddball being rated at 87Hz, so I didn't want to give myself any problems trying to reconfigure the VFD for an unknown motor. Thanks Moray ---In DynoMotion@yahoogroups.com, <tk@...> wrote:
Hi Moray,
Since it seems you will have a proper encoder on the Spindle, it would be best to operate closed loop. Use an axis channel and configure it much like a Servo axis. To go at a certain RPM command the axis to Jog at the appropriate encoder counts/sec. The VFD and KFLOP should not fight. KFLOP will adjust the DAC output to get the right speed just like any Servo. The Tuning (gains) will need to be set so the corrections are gradual enough such that too much
correction is made before the VFD has a chance to react, otherwise the system will become unstable. Can a negative voltage be applied to reverse the Spindle? Do you need to Reverse the spindle or servo it to a position?
Regards TK
|
|
Group: DynoMotion |
Message: 8582 |
From: Tom Kerekes |
Date: 11/5/2013 |
Subject: Re: Looking for some thread guidance |
Hi Moray,
If you need to control the direction relays you would need to write a small C program to take the Servo Output (ch->Output) and control the relays based on the sign of the output and send the magnitude to the DAC. Set the Axis Channel Output Mode to No Output. If switching direction back and forth quickly would cause a problem then you would need to write code to safeguard against that. if you need more details ask.
Regards TK
Group: DynoMotion |
Message: 8606 |
From: moray_cuthill |
Date: 11/11/2013 |
Subject: Re: Looking for some thread guidance |
Hi Tom, I got the spindle control tested this morning and got it working nicely once I tuned the figures down to suit the slowness of a VFD. Only question is, where best to put the code? I just had it as a seperate thread while testing it, but should I combine it with the spindle control thread, or with the main init thread? Thanks Moray ---In dynomotion@yahoogroups.com, <tk@...> wrote:
Hi Moray,
If you need to control the direction relays you would need to write a small C program to take the Servo Output (ch->Output) and control the relays based on the sign of the output and send the magnitude to the DAC. Set the Axis Channel Output Mode to No Output. If switching direction back and forth quickly would cause a problem then you would need to write code to safeguard against that. if you need more details ask.
Regards TK
From: "moray.cuthill@..." <moray.cuthill@...> To: DynoMotion@yahoogroups.com Sent: Tuesday, November 5, 2013 2:36 PM Subject: RE: Re: [DynoMotion] RE: Looking for some thread guidance
Hi Tom, the VFD is setup with two relays to control direction (FET2 + 3), along with a 0-10V feed (Analogue Out 2) Ultimately I'd like to be able to rigid tap to within a mm/one revolution target, however I'm not sure the current VFD and motor setup would be capable of it, so I'll be happy to settle for a reasonably accurate forward and reverse for now. The VFD is a good 20 years old (it's a KEB Combivert F0), and although capable of accepting a +/-10V signal according to the manual, the settings are locked out by an unknown password. I did consider changing it to use the +/-10V setting, but I had a search for a new VFD with a similar input and couldn't find any, so opted to stick with the more common 0-10V and relays for direction. I also considered wiping the settings completely, however the motor is a bit
oddball being rated at 87Hz, so I didn't want to give myself any problems trying to reconfigure the VFD for an unknown motor. Thanks Moray ---In DynoMotion@yahoogroups.com, <tk@...> wrote: Hi Moray,
Since it seems you will have a proper encoder on the Spindle, it would be best to operate closed loop.
Use an axis channel and configure it much like a Servo axis. To go at a certain RPM command the axis to Jog at the appropriate encoder counts/sec. The VFD and KFLOP should not fight. KFLOP will adjust the DAC output to get the right speed just like any Servo. The Tuning (gains) will need to be set so the corrections are gradual enough such that too much
correction is made before the VFD has a chance to react, otherwise the system will become unstable. Can a negative voltage be applied to reverse the Spindle? Do you need to Reverse the spindle or servo it to a position?
Regards TK
|
|
Group: DynoMotion |
Message: 8609 |
From: Tom Kerekes |
Date: 11/11/2013 |
Subject: Re: Looking for some thread guidance |
Hi Moray,
The Mach3 plugin sends messages (basically CW,CCW, Off, speed changes) to a single C program for Spindle Control. This should be a separate C program from your initialization program that is specified as the Spindle control program in the Mach3 | Dynomotion | Plugin Configuration. It should use a different Thread than Thread#1 which the initialization program always uses in case it happens to need to run at the same time. There are example
Mach3 Spindle Control Programs. The simplest is Spindlemach3.c which only prints the received messages from Mach3.
HTH Regards TK
Group: DynoMotion |
Message: 8612 |
From: moray_cuthill |
Date: 11/11/2013 |
Subject: Re: Looking for some thread guidance |
Hi Tom, what I've written so far simply takes the channel output, activates the relevant direction relay, and sets the DAC to the requested value, so the spindle channel acts just like a closed loop servo. I've only been testing by commanding Jogs through the console so far. I've already got the basic mach spindle example loading, it's just I wasn't sure whether I should have the above code sitting looping in the spindle thread, or if it should sit in the main init loop. Thanks Moray ---In DynoMotion@yahoogroups.com, <tk@...> wrote:
Hi Moray,
The Mach3 plugin sends messages (basically CW,CCW, Off, speed changes) to a single C program for Spindle Control. This should be a separate C program from your initialization program that is specified as the Spindle control program in the Mach3 | Dynomotion | Plugin Configuration. It should use a different Thread than Thread#1 which the initialization program always uses in case it happens to need to run at the same time. There are example
Mach3 Spindle Control Programs. The simplest is Spindlemach3.c which only prints the received messages from Mach3.
HTH Regards TK
From: "moray.cuthill@..." <moray.cuthill@...> To: DynoMotion@yahoogroups.com Sent: Monday, November 11, 2013 4:58 AM Subject: [DynoMotion] RE: Looking for some thread guidance
Hi Tom, I got the spindle control tested this morning and got it working nicely once I tuned the figures down to suit the slowness of a VFD. Only question is, where best to put the code? I just had it as a seperate thread while testing it, but should I combine it with the spindle control thread, or with the main init thread? Thanks Moray ---In dynomotion@yahoogroups.com, <tk@...> wrote: Hi Moray,
If you need to control the direction relays you would need to write a small C program to take the Servo Output (ch->Output) and control the relays based on the sign of the output and send the magnitude to the DAC. Set the Axis Channel Output Mode to No Output. If switching direction back and forth quickly would cause a problem then you would need to write code to safeguard against that. if you need more details ask.
Regards TK
From: "moray.cuthill@..." <moray.cuthill@...> To: DynoMotion@yahoogroups.com Sent: Tuesday, November 5, 2013 2:36 PM Subject: RE: Re: [DynoMotion] RE: Looking for some thread guidance
Hi Tom, the VFD is setup with two relays to control direction (FET2 + 3), along with a 0-10V feed (Analogue Out 2) Ultimately I'd like to be able to rigid tap to within a mm/one revolution target, however I'm not sure the current VFD and motor setup would be capable of it, so I'll be happy to settle for a reasonably accurate forward and reverse for now. The VFD is a good 20 years old (it's a KEB Combivert F0), and although capable of accepting a +/-10V signal according to the manual, the settings are locked out by an unknown password. I did consider changing it to use the +/-10V setting, but I had a search for a new VFD with a similar input and couldn't find any, so opted to stick with the more common 0-10V and relays for direction. I also considered wiping the settings completely,
however the motor is a bit
oddball being rated at 87Hz, so I didn't want to give myself any problems trying to reconfigure the VFD for an unknown motor. Thanks Moray ---In DynoMotion@yahoogroups.com, <tk@...> wrote: Hi Moray,
Since it seems
you will have a proper encoder on the Spindle, it would be best to operate closed loop.
Use an axis channel and configure it much like a Servo axis. To go at a certain RPM command the axis to Jog at the appropriate encoder counts/sec. The VFD and KFLOP should not fight. KFLOP will adjust the DAC output to get the right speed just like any Servo. The Tuning (gains) will need to be set so the corrections are gradual enough such that too much
correction is made before the VFD has a chance to react, otherwise the system will become unstable. Can a negative voltage be applied to reverse the Spindle? Do you need to Reverse the spindle or servo it to a position?
Regards TK
|
|
Group: DynoMotion |
Message: 8614 |
From: Tom Kerekes |
Date: 11/11/2013 |
Subject: Re: Looking for some thread guidance |
Hi Moray,
Oh, I forgot you needed that code to write to the relays and DAC to make the spindle servo work. That code needs to run forever continuously not just when the spindle settings change. So add that into a forever loop at the end of your Initialization.
The SpindleMach3JogsSteveRev2.c should then work with slight mods to:
#define SPINDLE_AXIS 6 // axis set up as Spindle, possibly Step/Dir or Servo #define FACTOR 2000000.0 // Converts fractional pulley speed to counts/sec (may be negative)
to perform the necessary Jog Commands and such.
HTH
Regards TK
Group: DynoMotion |
Message: 8632 |
From: moray_cuthill |
Date: 11/14/2013 |
Subject: Re: Looking for some thread guidance |
Hi Tom, I've got this sort of working. I changed the relevant constants so the commanded speed is correct, however the direction is causing problems. On an intial spindle/speed command, the correct Jog command is issued, however if I then command a change in speed the direction changes. This happens regardless of the initial direction. I added a couple extra lines to help with finding the issue, however I'm struggling and think it's possibly something to do with how I've got Mach set. If I issue the following commands- M3 S1000 M3 S2000 M4 S1000 M4 S2000 M5 I get the following in the console- Mach3 Notify Message=5, Direction=-1, Spindle Set to 0.200000 Spindle Direction=-1 Spindle Speed Set to 0.200000 Commanded Jog 33333.343750 Mach3 Notify Message=5, Direction=-1, Spindle Set to 0.200000 Spindle Direction=-1 Spindle Speed Set to 0.200000 Commanded Jog 33333.343750 Mach3 Notify Message=3, Direction= 0, Spindle Set to 0.200000 Spindle CW ON Mach3 Notify Message=5, Direction= 0, Spindle Set to 0.400000 Spindle Direction=0 Spindle Speed Set to 0.400000 Commanded Jog -66666.687500 Mach3 Notify Message=5, Direction= 0, Spindle Set to 0.200000 Spindle Direction=0 Spindle Speed Set to 0.200000 Commanded Jog -33333.343750 Mach3 Notify Message=5, Direction= 0, Spindle Set to 0.200000 Spindle Direction=0 Spindle Speed Set to 0.200000 Commanded Jog -33333.343750 Mach3 Notify Message=3, Direction= 1, Spindle Set to 0.200000 Spindle CCW ON Mach3 Notify Message=5, Direction= 1, Spindle Set to 0.400000 Spindle Direction=1 Spindle Speed Set to 0.400000 Commanded Jog 66666.687500 Mach3 Notify Message=4, Direction= 1, Spindle Set to 0.400000 Spindle Stop Mach3 Notify Message=4, Direction=-1, Spindle Set to 0.000000 Spindle Stop
Some commands appear to be sent twice, and the Jog switches direction even when the direction remains unchanged. Here's a copy of my modified spindlejog file - #include "KMotionDef.h" //Plugin Notifications and defines.. enum { EX_DDA , EX_VMS, EX_COMMAND, EX_SPINON, EX_SPINOFF, EX_SPINSPEED, EX_MOTORTUNED , EX_SETUP, EX_FEEDHOLD, EX_RUN, EX_ESTOP , EX_CONFIG }; #define SPINDLE_AXIS 2 // axis set up as Spindle, possibly Step/Dir or Servo #define FACTOR 166666.6 // Converts fractional pulley speed to counts/sec (may be negative) main() { int message = persist.UserData[0]; // Mach3 message ID int Direction = persist.UserData[1]; // Mach3 Spindle Direction float speed = *(float *)&persist.UserData[2]; // value stored is actually a float int DirFactor = 1; if (Direction==0) DirFactor=-1; // change Direcion 0 or 1 to DirFactor -1 or +1 printf("Mach3 Notify Message=%d, Direction=%2d, Spindle Set to %f\n",message,Direction,speed); switch (message) { case EX_SPINSPEED: printf("Spindle Direction=%d\n",Direction); printf("Spindle Speed Set to %f\n",speed); float jogspeed = speed*FACTOR*DirFactor; printf("Commanded Jog %f\n",jogspeed); Jog(SPINDLE_AXIS,speed*FACTOR*DirFactor); break; case EX_SPINON: if (Direction==0) { printf("Spindle CW ON\n"); } else if (Direction==1) { printf("Spindle CCW ON\n"); } break; case EX_SPINOFF: printf("Spindle Stop\n"); Jog(SPINDLE_AXIS,0.0); break; } }
Thanks Moray ---In dynomotion@yahoogroups.com, <tk@...> wrote:
Hi Moray,
Oh, I forgot you needed that code to write to the relays and DAC to make the spindle servo work. That code needs to run forever continuously not just when the spindle settings change. So add that into a forever loop at the end of your Initialization.
The SpindleMach3JogsSteveRev2.c should then work with slight mods to:
#define SPINDLE_AXIS 6 // axis set up as Spindle, possibly Step/Dir or Servo #define FACTOR 2000000.0 // Converts fractional pulley speed to counts/sec (may be negative)
to perform the necessary Jog Commands and such.
HTH
Regards TK
|
|
Group: DynoMotion |
Message: 8638 |
From: Tom Kerekes |
Date: 11/14/2013 |
Subject: Re: Looking for some thread guidance |
Hi Moray,
I doubt if it is a problem on the Mach3 side. The confusing thing is that Mach3 sends a direction as -1 if the spindle is currently off.
And in that case we don't want to set the Speed but rather remember it for when the Spindle is turned on.
There is a better example called: SpindleMach3JogsSteveRev2.c
I've also attached it. Please use that as a base.
Regards TK
Group: DynoMotion |
Message: 8648 |
From: Moray Cuthill |
Date: 11/15/2013 |
Subject: Re: Looking for some thread guidance [1 Attachment] |
Thanks for that Tom, tried it this morning and the spindle is now working how it should. Moray | | | | | | | | | | | | | |